package easy;

import java.util.HashSet;
import java.util.Set;

public class a面试题_02_01_移除重复节点 {
    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
        }
    }
    //递归
    Set<Integer> set = new HashSet();
    public ListNode removeDuplicateNodes(ListNode head) {
        if(head==null){
            return null;
        }
        if(set.contains(head.val)){
            return removeDuplicateNodes(head.next);
        }
        set.add(head.val);
        head.next = removeDuplicateNodes(head.next);
        return head;
    }
}
